Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D3D12: Fix out of bounds root parameter index when per-pixel lighting is disabled #13275

Merged

Conversation

Pokechu22
Copy link
Contributor

ROOT_PARAMETER statically allocates root parameter indexes, but DXContext::CreateGXRootSignature tries to skip ones that aren't relevant (those for bounding box and per-pixel lighting). b6d321b added an additional index for data related to graphics mods, which is always present (even if there are no graphics mods).

However, the logic for choosing what index to use didn't correctly handle per-pixel lighting being disabled, only bounding box being disabled. I've fixed that by moving the graphics mod one to the start of the list, so it doesn't have a dynamic offset. (I think it'd be better to make it optional too, but I'm not confident in my D3D12 abilities to do that right.)

Before:

No per-pixel lighting, no BB:

D3D12 ERROR: ID3D12CommandList::SetGraphicsRootConstantBufferView: RootParameterIndex [9] is out of bounds for the currently set root signature, which declares 9 root parameters. [ EXECUTION ERROR #710: SET_ROOT_CONSTANT_BUFFER_VIEW_INVALID]

No per-pixel lighting, yes BB:

D3D12 ERROR: ID3D12CommandList::SetGraphicsRootConstantBufferView: RootParameterIndex [10] is out of bounds for the currently set root signature, which declares 10 root parameters. [ EXECUTION ERROR #710: SET_ROOT_CONSTANT_BUFFER_VIEW_INVALID]

With per-pixel lighting enabled, this stopped happening. Now, things work properly in both cases.

@Pokechu22 Pokechu22 requested a review from iwubcode January 15, 2025 06:15
@Pokechu22 Pokechu22 force-pushed the d3d12-custom-root-param-index branch from 508a7b6 to 64514bd Compare January 15, 2025 06:30
@dolphin-ci
Copy link

dolphin-ci bot commented Jan 15, 2025

FifoCI detected that this change impacts graphical rendering. Here are the behavior differences detected by the system:

  • sw3-dt on ogl-lin-mesa: diff

automated-fifoci-reporter

@iwubcode
Copy link
Contributor

Thanks for doing this pokechu! This seems to work fine (tested with per pixel lighting on in my custom shader branch). I did see issues with cached pipelines not matching and therefore had to blow away my cached shaders. Error was:

D3D12 ERROR: ID3D12Device::Create*PipelineState: A pointer was provided to the D3D12_CACHED_PIPELINE_STATE struct which contains a cached PSO which does not match the rest of the description provided. The shaders and state descriptions must match what was originally used to create the cached PSO exactly. [ STATE_CREATION ERROR #887: CREATEPIPELINESTATE_CACHEDBLOBDESCMISMATCH]

I wonder if we should roll the pipeline version for this?

@Pokechu22
Copy link
Contributor Author

I don't have much D3D12 experience, but I thought that GX_PIPELINE_UID_VERSION was specifically for Dolphin's shader UID cache, which stores information about the GameCube state for all of the shaders that a game has used so that they can be recompiled on launch. I assume there is also a separate cache for the actual compiled shaders, which would be a per-backend thing (because we don't need to invalidate Vulkan shaders, for instance), but I'm not sure if that's actually the case or where that would be.

@iwubcode
Copy link
Contributor

Yes, we cache per graphics backend.

Looking at the disk cache code, it seems that when validating the header, the logic is only comparing the headers which has the git information and the magic key, so if users had two different builds the users would be fine. It's only because I tested in the same branch that there was issue.

In the past, I cheated and used GX_PIPELINE_UID_VERSION for any pipeline change to flush the cache. That was due to my fear and misunderstanding of how the cache code works. You are right, it is technically only supposed to be incremented for the game state.

I guess this is good to go then.

@Pokechu22 Pokechu22 merged commit 761e65e into dolphin-emu:master Jan 20, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants